import math
from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel
from sqlalchemy import func, select, Select
from sqlalchemy.ext.asyncio import AsyncSession
from typing import Optional, List
from utils.common_util import CamelCaseUtil

class DbUtil:
    """
    数据库工具类
    """
    
    @classmethod
    async def get_data(cls, db: AsyncSession, query: Select):
        """
        输入查询语句，返回数据列表结果

        :param db: orm对象
        :param query: sqlalchemy查询语句
        :return: 数据对象
        """
        query_result = await db.execute(query)
        data = []
        for row in query_result:
            if row and len(row) == 1:
                data.append(row[0])
            else:
                data.append(row)
        result = CamelCaseUtil.transform_result(data)

        return result
